package gold.digger;

/**
 * Created by fanzhenyu02 on 2020/2/28.
 */
public class LC07 {

    public int reverse_01(int x) {
        String numStr = String.valueOf(Math.abs(x));
        StringBuilder numSb = new StringBuilder();
        numSb.append(x < 0 ? "-" : "");
        boolean firstFlag = true;
        for (int i = numStr.length() - 1; i >= 0; --i) {
            if (numStr.charAt(i) == '0' && firstFlag) {
                continue;
            }
            numSb.append(numStr.charAt(i));
            firstFlag = false;
        }

        try {
            return Integer.parseInt(numSb.toString());
        } catch (Exception e) {
            return 0;
        }
    }

//    public int reverse(int x) {
//        int postive=Math.abs(x);
//        while()
//    }

    public static void main(String[] args) {
        LC07 an = new LC07();
        System.out.println(an.reverse_01(901000));
    }
}
